<HTML><HEAD><TITLE>domain_index(+Value, -Domain, -Index)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Comparing and Sorting</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>domain_index(+Value, -Domain, -Index)</H1>
Value is defined in Domain with positional number Index
<DL>
<DT><EM>Value</EM></DT>
<DD>Atomic term
</DD>
<DT><EM>Domain</EM></DT>
<DD>Variable or structure of the form Module:DomainName
</DD>
<DT><EM>Index</EM></DT>
<DD>Variable or integer starting from 1
</DD>
</DL>
<H2>Description</H2>
<P>
	Used to look up which domain a particular value belongs to, and
	which numerical index it has within this domain. Only domain definitions
	which are visible in the caller module are taken into account.
	</P><P>
	Domain is returned as a pair DefinitionModule:DomainName which
	unabiguously identifies the domain definition that contains the value.
	Index is unified with a natural number corresponding to the position
	of Value within that domain definition (starting from 1).
	</P>

<H3>Modes and Determinism</H3><UL>
<LI>domain_index(+, -, -) is semidet
</UL>
<H3>Modules</H3>
This predicate is sensitive to its module context (tool predicate, see @/2).
<H3>Fail Conditions</H3>
The value does not occur in any of the visible domain definitions
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>Value is not instantiated
<DT><EM>(5) type error </EM>
<DD>Value is not atomic
</DL>
<H2>Examples</H2>
<PRE>
    :- local domain(colour(red,green,blue)).

    :- export domain(vowel(a,e,i,o,u)).

    :- local domain(abc(a,b,c)).
    Domain value a not unique in module eclipse
    out of range in local domain(abc(a, b, c))
    Abort

    ?- domain_index(green, Domain, Index).
    Domain = eclipse : colour
    Index = 2
    Yes (0.00s cpu)

    ?- domain_index(a, Domain, Index).
    Domain = eclipse : vowel
    Index = 1
    Yes (0.00s cpu)

    ?- domain_index(b, Domain, Index).
    No (0.00s cpu)

    ?- domain_index(yellow, Domain, Index).
    No (0.00s cpu)
    </PRE>
<H2>See Also</H2>
<A HREF="../../kernel/termcomp/domain-1.html">domain / 1</A>, <A HREF="../../kernel/termcomp/current_domain-3.html">current_domain / 3</A>
</BODY></HTML>
